package org.example.servicecounselor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.model.manage.bean.po.CounselorMajor;
import org.example.model.manage.bean.po.Major;
import org.example.servicecounselor.mapper.CounselorMajorMapper;
import org.example.servicecounselor.mapper.MajorMapper;
import org.example.servicecounselor.service.CounselorMajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-08-03
 */
@Service
public class CounselorMajorServiceImpl extends ServiceImpl<CounselorMajorMapper, CounselorMajor> implements CounselorMajorService {

    @Autowired
    private CounselorMajorMapper counselorMajorMapper;

    @Autowired
    private MajorMapper majorMapper;

    @Override
    public List<Major> getMajorByCounselorId(Integer id) {
        List<CounselorMajor> list = counselorMajorMapper.selectList(new QueryWrapper<CounselorMajor>().eq("counselor_id", id));
        List<Major> majors = new ArrayList<>();
        for(CounselorMajor c : list) {
            majors.add(majorMapper.selectById(c.getMajorId()));
        }
        return majors;
    }
    
    @Override
    public Integer getCounselorIdByMajorId(Integer majorId) {
        CounselorMajor counselorMajor = counselorMajorMapper.selectOne(new QueryWrapper<CounselorMajor>().eq("major_id", majorId));
        return counselorMajor != null ? counselorMajor.getCounselorId() : null;
    }
}
